//
//  WelComeViewController.swift
//  SinaWeibo
//
//  Created by NeXTSTEP on 15/10/1.
//  Copyright © 2015年 NeXTSTEP. All rights reserved.
//

import UIKit
import SDWebImage


class WelComeViewController: BaseViewController {

    
    @IBOutlet weak var iconImage: UIImageView!
    
    @IBOutlet weak var welcomeLabel: UILabel!
    
    @IBOutlet weak var iconVIewBottom: NSLayoutConstraint!
    
    override func viewDidLoad() {
        super.viewDidLoad()
//        iconImage.layer.masksToBounds = true
//        iconImage.layer.cornerRadius = 45
        
        welcomeLabel.text = (UserAccount.shareUserAccount?.name ?? "") + " 欢迎归来"
        let imageURL = NSURL(string: UserAccount.shareUserAccount?.avatar_large ?? "")
        iconImage.sd_setImageWithURL(imageURL, placeholderImage: UIImage(named: "avatar_default_big"))
    }
    
    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        startWelcome()
    }
    
    private func startWelcome(){
        
        UIView.animateWithDuration(1.5, delay: 0, usingSpringWithDamping: 0.8, initialSpringVelocity: 6, options: [], animations: { () -> Void in
            
            self.iconVIewBottom.constant = self.view.bounds.height - self.iconVIewBottom.constant
            self.view.layoutIfNeeded()
            }) { (_) -> Void in
                UIView.animateWithDuration(0.5, animations: { () -> Void in
                    self.welcomeLabel.alpha = 1
                    }, completion: { (_) -> Void in
                        NSNotificationCenter.defaultCenter().postNotificationName(WBSwitchToRootVC, object: "Main")
                })
        }
    }

}
